package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;

import negocio.Area;
import persistencia.AreaDAO;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class CursosCrear extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JComboBox<Area> comboBox;
	
	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CursosCrear frame = new CursosCrear();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CursosCrear() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 300, 201);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		this.setTitle("Crear curso...");
		
		JLabel lblNombre = new JLabel("Nombre");
		lblNombre.setBounds(10, 45, 52, 14);
		contentPane.add(lblNombre);
		
		JLabel lblArea = new JLabel("Area");
		lblArea.setBounds(10, 70, 46, 14);
		contentPane.add(lblArea);
		
		textField = new JTextField();
		textField.setBounds(66, 42, 208, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton btnCrear = new JButton("Crear");
		btnCrear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				
			}
		});
		btnCrear.setBounds(86, 129, 89, 23);
		contentPane.add(btnCrear);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnCancelar.setBounds(185, 129, 89, 23);
		contentPane.add(btnCancelar);
		
		comboBox = new JComboBox<Area>();
		comboBox.setBounds(66, 70, 89, 20);
		llenarCombo();
		contentPane.add(comboBox);
		
		JButton btnAgregarArea = new JButton("Agregar Area...");
		btnAgregarArea.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				AreaCrear areaCrear = new AreaCrear();
				areaCrear.setVisible(true);
				
			}
		});
		btnAgregarArea.setBounds(165, 69, 109, 23);
		contentPane.add(btnAgregarArea);
	}
	
	private void llenarCombo()
	{
		AreaDAO adao = AreaDAO.getInstance();
		ArrayList<Area> areas = adao.getAll();
		for(Area a : areas)
		{
			comboBox.addItem(a);
		}
	}
}
